package oneroom.user.subway;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import oneroom.comm.IbatisLoader;

import com.ibatis.sqlmap.client.SqlMapClient;

public class subwayDao {
	private IbatisLoader 	iBatis;
	private SqlMapClient 	sqlMapper;
	
	public subwayDao(){
		this.sqlMapper = iBatis.setConfig();
	}
	
	public List getSubway(String subway,
						  String sort,			
					      int selectPage,
						  int pageSize){ 
		List returnValue = new ArrayList();
		/* 
		* 페이징 관련
		*/
		if (selectPage == 0) selectPage = 1;
		if (pageSize == 0) pageSize = 15;
		int startPos = ((selectPage-1)*pageSize);
		
		if(subway.equals("")){
			subway = null;
		}
		HashMap param = new HashMap();
		param.put("subway", subway);
		param.put("sort", sort);		
		param.put("startPos", startPos);
		param.put("pageSize", pageSize);
		try{
		returnValue = (List)sqlMapper.queryForList("subway.SUBWAYSECHE",param);
		}catch (Exception e) {
		// TODO: handle exception
		}
		return returnValue;
	
	}
	public int getCount(String subway){
		int returnValue = 0;
		if(subway.equals("")){
			subway = null;
		}
		HashMap param = new HashMap();
		param.put("subway", subway);
		try{
		returnValue =  ((Integer)sqlMapper.queryForObject("subway.SUBWAYCOUNT",param)).intValue();
		}catch (Exception e) {
		// TODO: handle exception
		}
		return returnValue;
		
	}
}
